class Solution {
public:
    int minMutation(string start, string end, vector<string>& bank) {
        unordered_set<string> hashset;
        for (auto n : bank) hashset.insert(n);
        if(hashset.find(end) == hashset.end()) return -1;
        queue<string> memo;
        memo.push(start);
        int steps = 0;
        while(!memo.empty())
        {
            ++steps;
            // vector<string> temp;
            int count = memo.size();
            for(int i = 0; i < count; i++)
            {
                for(int j = 0; j < 8; j++)
                {
                    char ori = memo.front()[j];
                    string a;
                    for(char c : {'A', 'C', 'G', 'T'})
                    { 
                        if(c == ori) continue;
                        a = memo.front();
                        a[j] = c;
                        if(a == end) return steps;
                        unordered_set<string>::iterator it = hashset.find(a);
                        if(it != hashset.end()) 
                        {
                            memo.push(a);
                            hashset.erase(it);
                        }
                    }
                }
                memo.pop();
            }
        }
        return -1;
    }
};
